﻿using System;
using System.Linq;
using Bids.Data;
using D=Bids.Core.DomainObjects;
using System.Web.Mvc;
using Bids.Service;

namespace Bids.Web.Controllers.Admin
{
    public class SystemController : BaseController<D.System>
    {

        ISystemService _iSysSrv;
        public SystemController(IRepository<D.System> iRpoSystem
            , ISystemService iSysSrv)
            : base(iRpoSystem)
        {
            _iSysSrv = iSysSrv;
        }
        /// <summary>
        /// 修改操作
        /// </summary>
        /// <param name="id"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateInput(false)]
        public override ActionResult Edit(int id, D.System moel)
        {
            try
            {
                var m = _iRpoT.Find(id);
                UpdateModel(m);
                _iRpoT.Update(m);
                SetMessage("修改成功", true);
                _iSysSrv.InitConfig();
                return RedirectToAction("Edit", new { ID = 1 });
            }
            catch (Exception e)
            {
                SetMessage(e.Message.ToString().Replace("\r\n", "\\r\\n"), false);
                return RedirectToAction("Edit", new { ID = 1});
            }
        }

    }
}
